<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分配权限</title>
    <link href="${request.contextPath}/static/ihomeStatic/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="${request.contextPath}/static/ihomeStatic/js/bootstrap-table/bootstrap-table.min.css">
    <link href="${request.contextPath}/static/ihomeStatic/css/font-awesome.min.css" rel="stylesheet">
    <link href="${request.contextPath}/static/ihomeStatic/css/animate.min.css" rel="stylesheet" type="text/css">
    <link href="${request.contextPath}/static/ihomeStatic/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet" type="text/css">
    <link href="${request.contextPath}/static/ihomeStatic/css/style.min.css" rel="stylesheet">
    <link href="${request.contextPath}/static/ihomeStatic/js/layer/theme/default/layer.css">
    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="${request.contextPath}/static/ihomeStatic/img/favicon.ico">
</head>
<body class="gray-bg">

<div class="wrapper">
    <div class="zTreeDemoBackground left">
        <ul id="treeDemo" class="ztree" style="background-color: #fcf6ff"></ul>
    </div>
    <div style="text-align: right;float:right;" >
        <button type="button" class="btn btn-primary" id="enter" onclick="enter()">确定</button>
        <button type="button" class="btn btn-default" id="cancel"  onclick="cancel()">取消</button>
    </div>
    <input type="hidden" id="ids" value="${ids}">
</div>
</body>
<script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery.ztree.core.js"></script>

<script src="${request.contextPath}/static/ihomeStatic/js/plugins/metisMenu/jquery.metisMenu.js" type="text/javascript"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/bootstrap.min.js"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/plugins/layer/layer.min.js"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/contabs.min.js" type="text/javascript"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/plugins/jqGrid/grid.locale-cn.js"></script>
<script src="${request.contextPath}/static/ihomeStatic/js/plugins/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery.ztree.excheck.min.js"></script>
<script type="text/javascript">

    $(function () {

        var setting = {

            check: {
                enable: true
            },
            view: {
                showIcon: true
            },
            callback:{
                onClick:zTreeOnClick
            },
            data: {
                simpleData: {
                    enable: true,
                    pIdKey:'pid'
                }
            }
        };
        function zTreeOnClick(event, treeId, treeNode, clickFlag) {
        }
        var id = $("#ids").val();
        $.ajax({
            url:"${request.contextPath}/roleManage/setPower?id="+id,
            success:function (data) {
                if (data!=null){
                    $.fn.zTree.init($("#treeDemo"), setting, data.treeList);
                    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                    // treeObj.checkNode(true);
                    $.each(data.roleRessour,function (index) {
                        var node = treeObj.getNodeByParam("id",data.roleRessour[index].menuId)
                        if (node!=null){
                            node.checked=true;
                            treeObj.updateNode(node,false);
                        }
                    });
                }
            },
            error:function (data) {
            }
        });
    });

    function enter() {
        var ids = [];
        var id = $("#ids").val();
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
        for(var i =0;i<nodes.length;i++){
            ids.push(nodes[i].id);
        }
        $.ajax({
            url:"${request.contextPath}/roleManage/addMenu",
            type:"GET",
            data:{ids:ids.toString(),id:id},
            success:function (data) {
                if (data){
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.$("#h1").val("1");
                    parent.layer.close(index);//关闭当前页
                }
            }

        });
    }

    function cancel() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.$("#h1").val("2");
        parent.layer.close(index);//关闭当前页
    }
</script>
</html>